﻿<!DOCTYPE html>
<html>
<#include "include/header.html"/>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<body>
<div class="page">
	<div class="content m">
	<#if commodity_type == '01' >
	<#if sendAddress??>
		<div class="mod_addr">
			<div class="t">送至</div>
			<div class="address">${sendAddress.province_name!}${sendAddress.city_name!}${sendAddress.country_name!}${sendAddress.geography_location!}</div>
			<div class="name">${sendAddress.receiver_name!}${sendAddress.telephone!}</div>
		</div>
		<#else>
		<div class="mod_addr">
			<div class="t">送至</div>
			<div class="address"></div>
			<div class="name"></div>
		</div>
		</#if>
		</#if>
		<div class="cart_confirm">
		<#list commodityList as a>
			<div class="item">
			<#if a.commodity_logo??>
				<img src="${server_uri!}${a.commodity_logo!}" class="pic">
				<#else>
				<img src="" class="pic">
				</#if>
				<div class="title">${a.commodity_name!}</div>
				<#if commodity_type == '01' >
				<div class="price">￥${a.per_price!}</div>
				<#else>
				<div class="price">￥1</div>
		        </#if>
				<div class="attr">型号:${a.version_type!}</div>
				<#if commodity_type == '01' >
                 <div class="attr">数量:${a.buy_num!}</div>				
                 <#else>
				<div class="attr">人次:${a.buy_num!}</div>
		        </#if>
			</div>
			</#list>
		</div>
		<#if commodity_type == '01' >
		<div class="mod_attr">
			<div class="item">
				<div class="fl">配送方式</div>
				<div class="fr">商家配送</div>
			</div>
		</div>
		</#if>
		<div class="mod_attr mod_large">
			<div class="item">
				<div class="fl">商品总额</div>
				<div class="fr">￥<span class="red" >${commodityBuyTotal.commodity_total_price!}</span></div>
			</div>
			<#if commodity_type == '01' >
			<div class="item" id="yunfei">
			</div>
			</#if>
		</div>	
	</div>

	<div class="footer">
		<div class="btn_group tab_c tab_c1">
			<div class="total" style="font-size:20px;">合计：￥<span id="totalPrice">${commodityBuyTotal.total_price!}</span></div>
			<a href="javascript:void(0);" class="btn btn_red btn_submit" onclick="submitOrder();">提交订单</a>
		</div>
	</div>
	
</div>
</body>
<script type="text/javascript">
$(function(){
var price="${commodityBuyTotal.total_price!}";
var send_cost="0";
<#if commodity_type == '01' >
   var strHtml="";
	strHtml+="<div class='fl'>运费</div>";
	if (price >=206) {
		strHtml+="<div class='fr'><span class='red' id='send_cost'>包邮</span></div>";
	}else{
		strHtml+="<div class='fr'>￥<span class='red' id='send_cost'>15</span></div>";
	}
	$("#yunfei").html(strHtml);
</#if>

<#if commodity_type == '01' >
if($("#send_cost").html()=="包邮"){
	 send_cost="0";
}else{
	 send_cost=$("#send_cost").html().replace("￥","");
}
</#if>
var total_id="${commodityBuyTotal.id!}";
var commodity_type="${commodity_type!}";
var address_id="";
if(commodity_type == 01){
<#if sendAddress??>
address_id="${sendAddress.id!}";
</#if>
}

submitOrder = function() {
	 if(commodity_type == 01){
	if(address_id=='' || address_id==undefined || address_id==null){
	   dialog('#ok',3000,"送货地址不能为空");
	   return;
       }
      }
	 $(".btn_submit").removeAttr("onclick");
     $(".btn_submit").removeClass("btn_red");
     $(".btn_submit").addClass(".btn_gray");
     $(".btn_submit").removeAttr("onclick");
		$.post("${ctx}/pay/createWXPayOrder",{
			commodity_id:"${id!}",
			totalPrice:price,
			buy_ids:"${buy_ids!}",
			version_id:"${version_id!}",
			countNum:"${commodityBuyTotal.buy_num!}",
			type:"${type!}",
			address_id:address_id,
			commodity_type:"${commodity_type!}",
			send_cost:send_cost,
			total_id:total_id,
			order_no:"${commodityBuyTotal.order_no!}",
			pay_order_no:"${commodityBuyTotal.pay_order_no!}"
		},function(data){
			 if(data.code==0){
					window.location.href="${ctx}/pay/aliPay?pay_money="+data.pay_money+"&order_id="+data.order_id+"&commodity_type=${commodity_type!}";
			 }else if(data.code==2){
					window.location.href="${ctx}/pay/accountPay?pay_money="+data.pay_money+"&order_id="+data.order_id+"&commodity_type=${commodity_type!}";
			 }else{
				    dialog('#ok',3000,data.msg);
			 }
			},'json');
	}
		
		$(".mod_addr").click(function(){
		window.location.href="${ctx}/mine/getAddr?buy_id="+total_id+"&forward_type=03"+"&is_order=01"+"&commodity_type=${commodity_type!}";
		})
		
});
</script>
</html>